﻿using System;
using System.Text.RegularExpressions;

namespace Util.TitleParser
{
    //Format S01E08
    class Parse_SssEee : ITitleParser
    {
        public Result ParseTitle(string title)
        {
            string Name, Details;
            long Season, Episode;

            Match m = Regex.Match(title, "[sS][0-2][0-9][eE][0-3][0-9]");
            if (!m.Success)
            {
                return null;
            }

            Season = long.Parse(m.Value.Substring(1, 2), System.Globalization.CultureInfo.InvariantCulture);
            Episode = long.Parse(m.Value.Substring(4, 2), System.Globalization.CultureInfo.InvariantCulture);
            Name = title.Substring(0, m.Index - 1);

            if (m.Index + 6 < title.Length)
            {
                Details = title.Substring(m.Index + 6);
            }
            else
            {
                Details = title;
            }
            return new Result(Name, Details, Season, Episode);
        }
    }
}
